<?php

namespace Home\Controller;

use Home\Controller\IndexController;

class ClientController extends IndexController {

    public function lst() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);
        $model = D('Client');
        $data = $model->search();

        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));
        //var_dump($data);
        //var_dump($page);
        $this->display();
    }

    public function edit() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        $id = I('get.id');
        if (IS_POST) {
            $model = D('Client');
            if ($model->create(I('post.'), 2)) {
                if ($model->save() !== FALSE) {
                    $this->success('修改成功！', U('edit', array('id' => I('post.id'),'p'=>$p)));
                    exit;
                }
            }
            $this->error($model->getError());
        }
        $cModel = M('Client');
        $data = $cModel->where(array('id' => array('eq', $id)))->find();
        //var_dump($data);
        $this->assign('data', $data);
        //取出地区选项
        $dModel = M('Dictionary');
        $dqdata = $dModel->where(array(
                    'category' => array('eq', '地区'),
                    'bar' => array('NEQ', '')
                ))->select();
        $this->assign('dqdata', $dqdata);
        //取出客户经理
        $aModel = M('Admin');
        $adata = $aModel->field('a.id,a.username')->alias('a')->join('left join crm_admin_role b on a.id=b.admin_id')->where('role_id=4')->select();
        $this->assign('adata', $adata);
        //取出客户等级
        $djdata = $dModel->where(array(
                    'category' => array('eq', '企业客户等级'),
                    'bar' => array('NEQ', '')
                ))->select();
        $this->assign('djdata', $djdata);
        //取出客户满意度
        $mydata = $dModel->where(array(
                    'category' => array('eq', '客户满意度'),
                    'bar' => array('NEQ', '')
                ))->select();
        $this->assign('mydata', $mydata);
        //取出客户信用度
        $xydata = $dModel->where(array(
                    'category' => array('eq', '客户信用度'),
                    'bar' => array('NEQ', '')
                ))->select();
        $this->assign('xydata', $xydata);

        $comeback = U('lst?p=' . I('get.p'));
        $this->assign('comeback', $comeback);
        $this->display();
    }


}
